package com.groupbuying.settleconsumer.mq;
import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Properties;


/**
 * 结算消息MQ配置文件
 * @Author cuich
 * @Date 2019-05-16
 */

@Configuration
public class SettleMQConsumer {

    @Autowired
    private SettleMessageListener settleMessageListener;

    public static final Logger LOGGER = LoggerFactory.getLogger(SettleMQConsumer.class);

    public SettleMQConsumer() {

    }

    @Bean
    public Consumer getYSAsynchronousSplitReceiptMQConsumerMsgListener() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.GROUP_ID, SettleMQConfig.GROUP_ID);
        properties.put(PropertyKeyConst.AccessKey, SettleMQConfig.ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, SettleMQConfig.SECRET_KEY);
        properties.put(PropertyKeyConst.NAMESRV_ADDR, SettleMQConfig.NAMESRV_ADDR);
        Consumer consumer = ONSFactory.createConsumer(properties);

        try {
            consumer.subscribe(SettleMQConfig.TOPIC, SettleMQConfig.ALL_TAG,settleMessageListener);
            consumer.start();
            LOGGER.info("SettleConsumer is start !!!  groupId:{" + SettleMQConfig.GROUP_ID+ "}");
        } catch (Exception var4) {
            LOGGER.error(String.format("SettleConsumer is error  groupId:{" + SettleMQConfig.GROUP_ID + "}", var4.getMessage(), var4));
        }
        return consumer;
    }
}

